package com.example.lenovo.wechat_view;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

public class ChatFragment extends Fragment {
    private View view;
    private RecyclerView mChatRecyclerView;
    private ChatAdapter mChatRecyclerAdapter;

    private List<Chat> chatList = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_chat, container, false);
        initRecyclerView();
        initChatData();

        return view;
    }

    private void initRecyclerView() {
        mChatRecyclerView = view.findViewById(R.id.chat_view);
        mChatRecyclerAdapter = new ChatAdapter(getActivity(), chatList);
        mChatRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        mChatRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
        mChatRecyclerView.setAdapter(mChatRecyclerAdapter);
    }

    private void initChatData() {
        for (int i = 0; i < 10; i++) {
            Chat chat = new Chat("龚喜辉", R.drawable.avatar);
            chatList.add(chat);
        }
    }
}
